<template>
    <div>
        <Card :bordered="true" dis-hover class="ivu-mb">
            <div slot="title" style="padding-top:4px;padding-bottom: 4px; ">
                <Avatar icon="md-apps" size="small" v-color="'#1890ff'" v-bg-color="'#e6f7ff'"/>
                <span class="ivu-pl-8">{{ getTitle }}</span>
                <span v-if="data && data.values">：{{ data.values.name }}</span>
            </div>
            <div>
                <div v-show="!data && !data.values">
                    <Alert>从菜单列表选择一项后，进行编辑</Alert>
                </div>
                <div v-show="data && data.values">
                    <cfgForm :cols="cols" :rules="rules" :columns="columns" ref="_frm" :data="data.values"></cfgForm>
                </div>
            </div>
<!--            <div v-show="data && data.values" style="margin-left: 100px;">-->
<!--                <Button type="primary" @click="ok">{{lang.edit}}</Button>-->
<!--            </div>-->
        </Card>
    </div>
</template>

<script>
export default {
    name: "editSubjectContent",
    data(){
        return {

        }
    },
    props: {
        classObject: {
            default: () => {
                return null;
            }
        },
        className: {
            default: () => {
                return '';
            }
        },
        type: {
            default: () => {
                return '';
            }
        },
        modelType: {
            default: () => {
                return '';
            }
        },
        data:{
            default: () => {
                return {};
            }
        },
        rules: {
            default: () => {
                return {};
            }
        },
        cols: {
            default: () => {
                return 2;
            }
        },
    },
    computed: {
        lang () {
            return {
                'en-US': {
                    edit: 'edit',
                    new: 'new',
                    detail: 'detail',
                    action: 'action',
                    submit: 'submit',
                    cancel: 'cancel',
                    save: 'save'
                },
                'zh-CN': {
                    edit: '编辑',
                    new: '添加',
                    detail: '查看',
                    action: '操作',
                    submit: '提交',
                    cancel: '取消',
                    save: '确定'
                }
            }[this.G_Locale]
        },
        // form中列字段
        columns () {
            let categoryColumns = [
                {
                    key: 'code',
                    title: {
                        'zh-CN': '编码',
                        'en-US': 'code'
                    }[this.G_Locale],
                    minWidth: 100,
                    align: 'center',
                    show: true
                },
                {
                    key: 'name',
                    title: {
                        'zh-CN': '名称',
                        'en-US': 'name'
                    }[this.G_Locale],
                    minWidth: 100,
                    align: 'center',
                    show: true
                },
                {
                    key: 'brevity',
                    title: {
                        'zh-CN': '简码',
                        'en-US': 'brevity'
                    }[this.G_Locale],
                    minWidth: 70,
                    align: 'center',
                    show: true
                },
                {
                    key: 'remark',
                    title: {
                        'zh-CN': '备注',
                        'en-US': 'remark'
                    }[this.G_Locale],
                    minWidth: 100,
                    align: 'center',
                    show: true
                }
            ];
            let subjectColumns = [
                {
                    key: 'code',
                    title: {
                        'zh-CN': '编码',
                        'en-US': 'code'
                    }[this.G_Locale],
                    minWidth: 100,
                    align: 'center',
                    config: { type: 'text' }
                },
                {
                    key: 'name',
                    title: {
                        'zh-CN': '名称',
                        'en-US': 'name'
                    }[this.G_Locale],
                    minWidth: 100,
                    align: 'center',
                    config: { type: 'text' }
                },
                {
                    key: 'brevity',
                    title: {
                        'zh-CN': '简码',
                        'en-US': 'brevity'
                    }[this.G_Locale],
                    minWidth: 70,
                    align: 'center',
                    config: { type: 'text' }
                },
                {
                    key: 'df_unitPrice',
                    title: {
                        'zh-CN': '单价',
                        'en-US': 'unitPrice'
                    }[this.G_Locale],
                    minWidth: 70,
                    align: 'center',
                    config: { type: 'number',precision:2,step:0.5 }
                },
                {
                    key: 'sf_unit',
                    title: {
                        'zh-CN': '单位',
                        'en-US': 'unit'
                    }[this.G_Locale],
                    minWidth: 70,
                    align: 'center',
                    config: { type: 'text' }
                },
                /* {
                    key: 'df_targetCoef',
                    title: {
                        'zh-CN': '指标系数',
                        'en-US': 'targetCoef'
                    }[this.G_Locale],
                    minWidth: 70,
                    align: 'center',
                    config: { type: 'number',precision:2,step:0.5 }
                },
                {
                    key: 'df_metalBalanceCoef',
                    title: {
                        'zh-CN': '平衡系数',
                        'en-US': 'metalBalanceCoef'
                    }[this.G_Locale],
                    minWidth: 70,
                    align: 'center',
                    config: { type: 'number',precision:2,step:0.5 }
                },
                {
                    key: 'df_calculateCoef',
                    title: {
                        'zh-CN': '期末系数',
                        'en-US': 'calculateCoef'
                    }[this.G_Locale],
                    minWidth: 70,
                    align: 'center',
                    config: { type: 'number',precision:2,step:0.5 }
                }, */
                {
                    key: 'sf_accountingSubject',
                    title: {
                        'zh-CN': '会计科目',
                        'en-US': 'accountingSubject'
                    }[this.G_Locale],
                    minWidth: 70,
                    align: 'center',
                    config: { type: 'text' }
                },
                {
                    key: 'remark',
                    title: {
                        'zh-CN': '备注',
                        'en-US': 'remark'
                    }[this.G_Locale],
                    minWidth: 100,
                    align: 'center',
                    config: { type: 'textarea' }
                }
            ];
            if(!!this.data.values&&this.data.values.nodeType=='subject'){
                return subjectColumns;
            }else{
                return categoryColumns;
            }
        },
        getTitle(){
            if(!!this.data.values&&this.data.values.nodeType=='subject'){
                return '查看成本科目';
            }else if(!!this.data.values&&this.data.values.nodeType=='center'){
                return '查看成本中心';
            }else{
                return '查看成本类型';
            }
        }
    },
    methods:{
        /**
         * 提交添加或修改数据
         */
        ok () {
            this.loading = true;
            this.$refs._frm.$refs.form.validate(valid => {
                if (valid) {
                    let data = this.tools.lodash.cloneDeep(this.data)
                    this.$emit('submit', data);
                }
            });
        }
    }
}
</script>
